﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlackBBS.Enums;
using BlackBBS.Models.Data;
using BlackBBS.Infrastructure.TelnetProtocol;

namespace BlackBBS.Helpers
{
    public static  class ANSIColorHelper
    {
        public static string AnsiColorMessage(string message, ANSIForeGroundColors foreground, ANSIBackgroundColors background, bool includeCRLF = false)
        {
            return string.Format("{0}{1}{2}{3}",
                                     ANSIColorHelper.AnsiColor(foreground, background),
                                     message,
                                     ANSIColorHelper.ResetToDefault(),
                                     includeCRLF ? "\r\n" : string.Empty);
        }
        public static string AnsiColor(ANSIForeGroundColors foreground, ANSIBackgroundColors background)
        {            
            return string.Format("{0}[{1};{2}m", ANSICharacterCodes.ANSIEsc, (int)foreground, (int)background);
        }
        public static string AnsiColor(ANSITextAttributes attribute, ANSIForeGroundColors foreground, ANSIBackgroundColors background)
        {
            return string.Format("{0}[{1};{2};{3}m", ANSICharacterCodes.ANSIEsc, (int)attribute, (int)foreground, (int)background);
        }
        public static string ResetToDefault()
        {
            return AnsiColor(ANSITextAttributes.AllOff, ANSIForeGroundColors.White, ANSIBackgroundColors.Black);
        }

        public static string CleanInput(string input)
        {
            input = input.Replace("(0x (B", "|");
            input = input.Replace("(0 x(B", "|");
            input = input.Replace(")0=>", "");
            input = input.Replace("[0m>", "");
            input = input.Replace("7[7m", "[");
            input = input.Replace("[0m*8[7m", "]");
            input = input.Replace("[0m", "");
           // input = input.Replace(ANSICharacterCodes.KeyCr, "");
          //  input = input.Replace(ANSICharacterCodes.KeyLn, "");
            return input;
        }


    }
}
